package ru.lukyanets.transmission.protocol.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.core.type.TypeReference;
import ru.lukyanets.transmission.protocol.model.port.PortState;
import ru.lukyanets.transmission.protocol.model.session.Session;
import ru.lukyanets.transmission.protocol.model.session.stats.SessionStats;
import ru.lukyanets.transmission.protocol.model.torrent.AddResponse;
import ru.lukyanets.transmission.protocol.model.torrent.Torrents;


/**
 * @author slukyanets
 */
public class Method<T> {
    public static final Method<Torrents> TORRENT_GET = new Method<>("torrent-get", new TypeReference<>() {});
    public static final Method<Empty> TORRENT_SET = new Method<>("torrent-set", new TypeReference<>(){});
    public static final Method<AddResponse> TORRENT_ADD = new Method<>("torrent-add", new TypeReference<>(){});
    public static final Method<Empty> TORRENT_REMOVE = new Method<>("torrent-remove", new TypeReference<>(){});
    public static final Method<Empty> TORRENT_SET_LOCATION = new Method<>("torrent-set-location", new TypeReference<>(){});
    public static final Method<Empty> TORRENT_RENAME_PATH = new Method<>("torrent-rename-path", new TypeReference<>(){});
    public static final Method<Empty> TORRENT_START = new Method<>("torrent-start", new TypeReference<>(){});
    public static final Method<Empty> TORRENT_START_NOW = new Method<>("torrent-start-now", new TypeReference<>(){});
    public static final Method<Empty> TORRENT_STOP = new Method<>("torrent-stop", new TypeReference<>(){});
    public static final Method<Empty> TORRENT_VERIFY = new Method<>("torrent-verify", new TypeReference<>(){});
    public static final Method<Empty> TORRENT_RENOUNCE = new Method<>("torrent-reannounce", new TypeReference<>(){});
    public static final Method<Empty> SESSION_SET = new Method<>("session-set", new TypeReference<>(){});
    public static final Method<Session> SESSION_GET = new Method<>("session-get", new TypeReference<>(){});
    public static final Method<SessionStats> SESSION_STATS = new Method<>("session-stats", new TypeReference<>(){});
    public static final Method<Empty> SESSION_CLOSE = new Method<>("session-close", new TypeReference<>(){});
    public static final Method<Integer> BLOCKLIST_UPDATE = new Method<>("blocklist-update", new TypeReference<>(){});
    public static final Method<PortState> PORT_TEST = new Method<>("port-test", new TypeReference<>(){});
    public static final Method<Empty> QUEUE_MOVE_TOP = new Method<>("queue-move-top", new TypeReference<>(){});
    public static final Method<Empty> QUEUE_MOVE_UP = new Method<>("queue-move-up", new TypeReference<>(){});
    public static final Method<Empty> QUEUE_MOVE_DOWN = new Method<>("queue-move-down", new TypeReference<>(){});
    public static final Method<Empty> QUEUE_MOVE_BOTTOM = new Method<>("queue-move-bottom", new TypeReference<>(){});
    public static final Method<Empty> FREE_SPACE = new Method<>("free-space", new TypeReference<>(){}); // TODO replace with List<String, Long>

    private final String method;
    private final TypeReference<TResponse<T>> responseType;

    @SuppressWarnings("unchecked")
    private Method(String method, TypeReference<TResponse<T>> responseType) {
        this.method = method;
        this.responseType = responseType;
    }

    public String getMethod() {
        return method;
    }

    public TypeReference<TResponse<T>> getResponseType() {
        return responseType;
    }

    @SuppressWarnings("WeakerAccess")
    @JsonIgnoreProperties(ignoreUnknown = true)
    public static class Empty {
    }
}
